﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BCS.Business;

namespace BCS.WinFormAppGui
{
        public partial class QueryForm : Form
        {
                private BusinessCache cache = BusinessCache.Instance;

                public QueryForm()
                {
                        InitializeComponent();
                }

                private void Form_Load(object sender, EventArgs e)
                {
                        TeamComboBox.Items.Add("甲班");
                        TeamComboBox.Items.Add("乙班");
                        TeamComboBox.Items.Add("丙班");

                        TeamComboBox.SelectedIndex = 0;
                }

                private void TeamQueryButton_Click(object sender, EventArgs e)
                {
                        DateTime qt = TeamDateTimePicker.Value;
                        DateTime QueryTime = new DateTime(qt.Year,qt.Month, qt.Day);
                        
                        String teamName = TeamComboBox.SelectedItem.ToString();

                        PDFForm form = new PDFForm();
                        form.PdfFile = TeamQueryPDF.CreatePdfDocument(QueryTime, teamName);

                        form.ExportButton.Visible = false;

                        form.ShowDialog();
                }

                private void SpanQueryButton_Click(object sender, EventArgs e)
                {
                        DateTime st = StartDateTimePicker.Value;
                        DateTime StartTime = new DateTime(st.Year, st.Month, st.Day, st.Hour, 0, 0);

                        DateTime et = EndDateTimePicker.Value;
                        DateTime EndTime = new DateTime(et.Year, et.Month, et.Day, et.Hour, 0, 0);

                        if (StartTime > EndTime)
                        {
                                MessageBox.Show("结束时间必须大于起始时间");
                                return;
                        }

                        PDFForm  form = new PDFForm();
                        form.PdfFile = SpanQueryPDF.CreatePdfDocument(StartTime, EndTime);
                        form.ShowDialog();
                }

                private void SpanMemoQueryButton_Click(object sender, EventArgs e)
                {
                        DateTime st = StartDateTimePicker.Value;
                        DateTime StartTime = new DateTime(st.Year, st.Month, st.Day, st.Hour, 0, 0);

                        DateTime et = EndDateTimePicker.Value;
                        DateTime EndTime = new DateTime(et.Year, et.Month, et.Day, et.Hour, 0, 0);

                        if (StartTime > EndTime)
                        {
                                MessageBox.Show("结束时间必须大于起始时间");
                                return;
                        }

                        PDFForm form = new PDFForm();
                        form.PdfFile = SpanMemoQueryPDF.CreatePdfDocument(StartTime, EndTime);
                        form.ShowDialog();
                }
        }
}
